package com.zb.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zb.Service.DictionaryService;
import com.zb.Service.RoomkindService;
import com.zb.Service.RoomorderService;
import com.zb.Service.UserService;
import com.zb.entity.Dictionary;
import com.zb.entity.Roomkind;
import com.zb.entity.Roomorder;
import com.zb.entity.User;

@Scope("prototype")
@Component
@RequestMapping("/roomorder")
public class RoomOrderController {
	@Resource
	private RoomorderService rs;
	@Resource
	private UserService us;
	@Resource
	private RoomkindService ks;
	@Resource
	private DictionaryService ds;

	@RequestMapping(params = "op=save")
	public String tosave(int userid, int did, String starttime, String endtime,
			int rid,ModelMap modelMap) {
		User user = us.getUserById(userid);
		Dictionary dictionary = ds.getDictionaryById(did);
		Roomkind roomkind = ks.getRoomKindById(rid);
		Roomorder r = new Roomorder();
		r.setDictionary(dictionary);
		r.setUser(user);
		r.setEndtime(endtime);
		r.setStarttime(starttime);
		r.setRoomkind(roomkind);
		rs.saveRoomorderMapper(r);
		modelMap.put("msg", "操作成功");
		return "room";
	}

	@RequestMapping(params = "op=show")
	@ResponseBody
	public List<Roomorder> toShow(String username, String roomname,
			Integer dicid, String start, String end) {
		List<Roomorder> rlist = rs.getRoomorderok(username, roomname, dicid, start, end);
		return rlist;
	}
	@RequestMapping(params="op=delete")
	public String todelete(int id,ModelMap modelMap){
		rs.deleteRoomOrder(id);
		modelMap.put("msg", "操作成功");
		return "room";
	}
	
}
